package maiyatian.videolive.application;

import android.app.Application;
import android.content.Context;
import android.widget.Toast;

import org.xutils.x;

import maiyatian.videolive.common.BaseAppManager;

/**
 * Created by 王中阳 on 2016/5/9.
 */
public class IApp extends Application {
    private static IApp instance;
    private Toast mToast = null; //优化toast，避免阻塞

    @Override
    public void onCreate() {
        super.onCreate();
        //初始化XUtils3
        x.Ext.init(this);
        //设置debug模式
        x.Ext.setDebug(true);
    }

    public IApp() {
    }

    //单例模式中获取唯一的IApp实例 避免并发
    public static IApp getInstance() {
        if (null == instance) {
            instance = new IApp();
        }
        return instance;
    }

    public void showToast(Context context, String text) {
        if (mToast == null) {
            mToast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
        } else {
            mToast.setText(text);
            mToast.setDuration(Toast.LENGTH_SHORT);
        }

        mToast.show();
    }


    public void exitApp() {
        BaseAppManager.getInstance().clear();
        System.gc();
        android.os.Process.killProcess(android.os.Process.myPid());
    }
}
